package com.aaa.java09;

/**
 * @author ：Teacher陈（86521760@qq.com）
 * @date ：Created in 2022/7/12 14:42
 * @description：
 * @modified By：
 * @version:
 */
public class Test {
    public static void main(String[] args) {
        Dog[] dogs= new Dog[3];
        Dog dog1= new Dog("旺财1",12,"白色","中华财犬");
        Dog dog2= new Dog("旺财2",8,"白色","中华财犬");
        Dog dog3= new Dog("旺财3",16,"白色","中华财犬");
        dogs[0]=dog1;
        dogs[1]=dog2;
        dogs[2]=dog3;
        System.out.println("排序之前");
        for (Dog dog : dogs) {
            System.out.println(dog);
        }
        for (int i = 1; i <dogs.length ; i++) {
            for (int j = 0; j < dogs.length - i; j++) {
                if(dogs[j].getAge()>dogs[j+1].getAge()){
                    Dog temp= new Dog();
                    temp=dogs[j];
                    dogs[j]=dogs[j+1];
                    dogs[j+1]=temp;
                }
            }
        }
        System.out.println("排序之后");
        for (Dog dog : dogs) {
            System.out.println(dog);
        }
    }
}
